﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Public.Tools;
using MB.Orm.Common;
using System.Data;
using Business;
using Model;
using Public;
using wochu.DPS.API.Infrastructure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace wochu.DPS.API.Controllers
{
    public class OrdersController : ApiController
    {
        /// <summary>
        /// 总线获取订单信息接口
        /// </summary>
        /// <param name="rationDate"></param>
        /// <param name="batchNumber"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetOrderInfo(DateTime rationDate, string batchNumber,string orderNo)
        {
            if (rationDate == null || rationDate==DateTime.MaxValue || rationDate== DateTime.MinValue)
                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0001"));
            MB.Util.TraceEx.Write(rationDate.ToString());
            try
            {
                var data = new BOrderPick().GetOrderInfo(rationDate, batchNumber, orderNo);
                if (data == null || data.Count <= 0)
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0002"));
                }
                return ResultsExtensions.GetSuccessJson(data);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0003"));
            }
        }
        [HttpGet]
        public HttpResponseMessage GetAllOrderInfo(DateTime rationDate)
        {
            if (rationDate == null || rationDate == DateTime.MaxValue || rationDate == DateTime.MinValue)
                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0001"));
            MB.Util.TraceEx.Write(rationDate.ToString());
            try
            {
                var data = new BOrderPick().GetOrderInfo(rationDate);
                if (data == null || data.Count <= 0)
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0002"));
                }
                return ResultsExtensions.GetSuccessJson(data);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0003"));
            }
        }

        /// <summary>
        /// 总线获取订单信息接口
        /// </summary>
        /// <param name="rationDate"></param>
        /// <param name="batchNumber"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetOrderInfoByOrderNO( string orderNo)
        {
            try
            {
                var data = new BOrderPick().GetOrderInfobyOrderNO(orderNo);
                if (data == null || data.Count <= 0)
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0002"));
                }
                return ResultsExtensions.GetSuccessJson(data);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0003"));
            }
        }

        [HttpGet]
        public HttpResponseMessage GetOrderInfoByFboxNO(string FboxNo)
        {
            try
            {
                SysSetting sett = new SysSetting();
                string OrderNO = new BOrderPick().GetOrderNOByFboxNo(FboxNo);
                if (string.IsNullOrEmpty(OrderNO))
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "发货箱：" + FboxNo + "未绑定订单信息！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                var data = new BOrderPick().GetOrderInfobyOrderNO(OrderNO);
                if (data == null || data.Count <= 0)
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0002"));
                }
                return ResultsExtensions.GetSuccessJson(data);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0003"));
            }
        }

        /// <summary>
        /// 总线写入订单到dps
        /// </summary>
        /// <param name="orders"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage WriteOrdersToDps(List<OrderInfo> orders)
        {
            ResultModel res = new BOrderPick().WriteOrdersToDps(orders);
            SysSetting sett = new SysSetting();
            if (res.RESULT.Equals("1"))
            {
                return ResultsExtensions.GetSuccessJson(res);
            }
            else
            {
                sett.Key = res.RESULT;
                sett.Value = res.MESSAGE;
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        /// <summary>
        /// 周转箱绑定商品
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage BindZboxAndGoods(int UserID, string UserName, string goodsCode, string ZboxNo)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (string.IsNullOrEmpty(goodsCode))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "商品编码为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            int GoodsID = new BGoods().GetGoodsID(goodsCode);
            if (string.IsNullOrEmpty(GoodsID.ToString()) || GoodsID == 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "商品编码不存在！";
                return ResultsExtensions.GetFailJson(sett);
            }
            if (string.IsNullOrEmpty(ZboxNo))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "周转箱编码为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            _result = new BBoxOrder().SetZboxSkuRelation(GoodsID, ZboxNo, UserID, UserName);
            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "绑定失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }


        /// <summary>
        /// 绑定发货箱与订单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage BindFBoxAndOrder(int UserID, string UserName,List<KeyValueModel> OrderNOandFboxNO)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (OrderNOandFboxNO == null || OrderNOandFboxNO.Count <= 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "请求数据格式错误，请检查提交信息！";
                return ResultsExtensions.GetFailJson(sett);
            }
            foreach (KeyValueModel item in OrderNOandFboxNO)
            {
                string OrderNO = item.Key.ToString();
                if (string.IsNullOrEmpty(OrderNO))
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "订单编号为空！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                var OrderList = new BOrder().getPindentInfo(OrderNO);
                if (OrderList == null || OrderList.Count <= 0)
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "订单拣货任务不存在！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                var FboxNOs = JsonConvert.DeserializeObject<List<string>>(item.Value.ToString());
                //List<string> FboxNOs = (List<string>)item.Value;
                if (FboxNOs == null || FboxNOs.Count<=0)
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "订单:" + OrderNO + "的发货箱编码为空！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                foreach (string FboxNO in FboxNOs)
                {
                    _result = new BBoxOrder().SetFboxOrderRelation(OrderNO, FboxNO,UserID,UserName);
                    if (!_result)
                    {
                        sett.Key = Consts.strFalse;
                        sett.Value = "绑定失败，请联系管理员";
                        return ResultsExtensions.GetFailJson(sett);
                    }
                }
            }
                
            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "绑定失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }


        /// <summary>
        /// 绑定发货箱与订单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage AddFBoxToOrder(int UserID, string UserName,string OrderNO, string FboxNO)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (string.IsNullOrEmpty(OrderNO))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "订单编号为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            var OrderList = new BOrder().getPindentInfo(OrderNO);
            if (OrderList == null || OrderList.Count <= 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "订单拣货任务不存在！";
                return ResultsExtensions.GetFailJson(sett);
            }
            if (string.IsNullOrEmpty(FboxNO))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "发货箱编码为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            _result = new BBoxOrder().SetFboxOrderRelation(OrderNO, FboxNO, UserID, UserName);
            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "绑定失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        /// <summary>
        /// 解绑原有订单和发货箱关系，重新绑定新的发货箱
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="UserName"></param>
        /// <param name="OrderNO"></param>
        /// <param name="FboxNOs"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage ChangeFboxToOrder(int UserID, string UserName, string OrderNO, List<string> FboxNOs)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (FboxNOs == null || FboxNOs.Count <= 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "请求数据发货箱格式错误，请检查提交信息！";
                return ResultsExtensions.GetFailJson(sett);
            }
            if (string.IsNullOrEmpty(OrderNO))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "订单编号为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            var OrderList = new BOrder().getPindentInfo(OrderNO);
            if (OrderList == null || OrderList.Count <= 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "订单拣货任务不存在！";
                return ResultsExtensions.GetFailJson(sett);
            }
            //var FboxNOs = JsonConvert.DeserializeObject<List<string>>(item.Value.ToString());
            //List<string> FboxNOs = (List<string>)item.Value;
            _result = new BBoxOrder().deleteFboxOrderrelation(OrderNO, UserID, UserName);
            if (_result)
            {
                foreach (string FboxNO in FboxNOs)
                {
                    _result = new BBoxOrder().SetFboxOrderRelation(OrderNO, FboxNO, UserID, UserName);
                    if (!_result)
                    {
                        sett.Key = Consts.strFalse;
                        sett.Value = "绑定新发货箱失败，请联系管理员";
                        return ResultsExtensions.GetFailJson(sett);
                    }
                }
            }
            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "换绑发货箱失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        /// <summary>
        /// 解绑原有订单和发货箱关系
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="UserName"></param>
        /// <param name="OrderNO"></param>
        /// <param name="FboxNOs"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage deleteFboxToOrder(int UserID, string UserName, List<KeyValueModel> OrderNOandFboxNO)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (OrderNOandFboxNO == null || OrderNOandFboxNO.Count <= 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "请求数据格式错误，请检查提交信息！";
                return ResultsExtensions.GetFailJson(sett);
            }
            foreach (KeyValueModel item in OrderNOandFboxNO)
            {
                string OrderNO = item.Key.ToString();
                if (string.IsNullOrEmpty(OrderNO))
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "订单编号为空！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                var OrderList = new BOrder().getPindentInfo(OrderNO);
                if (OrderList == null || OrderList.Count <= 0)
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "订单拣货任务不存在！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                var FboxNOs = JsonConvert.DeserializeObject<List<string>>(item.Value.ToString());
                //List<string> FboxNOs = (List<string>)item.Value;
                if (FboxNOs == null || FboxNOs.Count <= 0)
                {
                    sett.Key = Consts.strFalse;
                    sett.Value = "订单:" + OrderNO + "的发货箱编码为空！";
                    return ResultsExtensions.GetFailJson(sett);
                }
                foreach (string FboxNO in FboxNOs)
                {
                    _result = new BBoxOrder().deleteFboxOrderPair(OrderNO,FboxNO, UserID, UserName);
                    if (!_result)
                    {
                        sett.Key = Consts.strFalse;
                        sett.Value = "解绑失败，请联系管理员";
                        return ResultsExtensions.GetFailJson(sett);
                    }
                }
            }

            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "解绑失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        /// <summary>
        /// 核单
        /// </summary>
        /// <param name="BoxNO"></param>
        /// <param name="UserID"></param>
        /// <param name="UserName"></param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage ConfirmCheckOrder(DateTime RationDate ,string FBoxNO, int UserID, string UserName,string CHECKLOCATION)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (string.IsNullOrEmpty(FBoxNO))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "发货箱编码为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            var OrderList = new BOrderPick().GetOrderInfo(FBoxNO);
            if (OrderList == null || OrderList.Count<=0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "当前发货箱未绑定订单！";
                return ResultsExtensions.GetFailJson(sett);
            }
            ResultModel checkOrderResult = new BOrderPick().CheckOrderIsChanged(RationDate, OrderList[0].ORDERNO);
            if (checkOrderResult.RESULT == "1")
            {
                sett.Key = Consts.strFalse;
                sett.Value = checkOrderResult.MESSAGE;
                return ResultsExtensions.GetFailJson(sett);
            }
            if (OrderList[0].STATUS.ToString() == "2")
            {
                _result = true;
            }
            _result = new BOrderPick().ChangeDPSOrderStatus(OrderList[0].ORDERNO, 2);
            _result = new BOrderPick().CheckHistoryLog(OrderList[0].ORDERNO, FBoxNO, UserID, UserName, CHECKLOCATION);
            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(OrderList);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "核单失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        [HttpGet]
        public HttpResponseMessage CheckOrderIsChanged(DateTime rationDate, string BoxNo)
        {
            if (string.IsNullOrWhiteSpace(BoxNo))
                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0005"));
            MB.Util.TraceEx.Write(BoxNo);
            ResultModel res = new BOrderPick().CheckOrderIsChanged(rationDate, BoxNo);
            SysSetting sett = new SysSetting();
            if (res.RESULT.Equals("0"))
            {
                return ResultsExtensions.GetSuccessJson(res);
            }
            else
            {
                sett.Key = res.RESULT;
                sett.Value = res.MESSAGE;
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        [HttpGet]
        public HttpResponseMessage CheckFboxStatus(string FboxNO)
        {
            MB.Util.TraceEx.Write(FboxNO);
            ResultModel res = new BOrderPick().CheckFboxIsChanged(FboxNO);
            SysSetting sett = new SysSetting();
            if (res.RESULT.Equals("1"))
            {
                sett.Key = res.RESULT;
                sett.Value = res.MESSAGE;
                return ResultsExtensions.GetFailJson(sett);
            }
            else
            {
                sett.Key = res.RESULT;
                sett.Value = res.MESSAGE;
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        /// <summary>
        /// 根据日期、商品和批次号，查询商品信息
        /// </summary>
        /// <param name="rationDate"></param>
        /// <param name="batchNumber"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetGoodsInfo(DateTime rationDate, string batchNumber, string GoodsCode)
        {
            SysSetting sett = new SysSetting();
            bool _result = false;
            if (rationDate==null)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "配送日期为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            if (string.IsNullOrEmpty(batchNumber))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "波次号为空！";
                return ResultsExtensions.GetFailJson(sett);
            }
            if (string.IsNullOrEmpty(GoodsCode))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "商品号为空！";
                return ResultsExtensions.GetFailJson(sett);
            }

            var resultList = new BOrderPick().GetSumOrderItem(rationDate.ToString("yyyy-MM-dd"),batchNumber, GoodsCode);
            if (resultList != null && resultList.Tables.Count > 0 && resultList.Tables[0].Rows.Count > 0)
                _result = true;
            if (_result)
            {
                return ResultsExtensions.GetSuccessJson(resultList);
            }
            else
            {
                sett.Key = Consts.strFalse;
                sett.Value = "请求失败，请联系管理员";
                return ResultsExtensions.GetFailJson(sett);
            }
        }

        /// <summary>
        /// 获取冻品拣货信息
        /// </summary>
        /// <param name="rationDate"></param>
        /// <param name="batchNumber"></param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetFrozenGoodsInfo(DateTime rationDate, string batchNumber)
        {


            if (rationDate == null || rationDate == DateTime.MaxValue || rationDate == DateTime.MinValue)
                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0001"));
            MB.Util.TraceEx.Write(rationDate.ToString());
            try
            {
                var ds = new BOrderPick().GetFrozenGoodsInfo(rationDate, batchNumber);
                if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0004"));
                }
                return ResultsExtensions.GetSuccessJson(ds.Tables[0]);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0005"));
            }
        }

        [HttpGet]
        public HttpResponseMessage GetFinishedOrderInfo(DateTime rationDate, string batchNumber,int subNObegin,int subNOend)
        {


            if (rationDate == null || rationDate == DateTime.MaxValue || rationDate == DateTime.MinValue)
                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0003"));
            MB.Util.TraceEx.Write(rationDate.ToString());
            try
            {
                var ds = new BOrderPick().GetOrderFinishedInfoList(rationDate, batchNumber, subNObegin, subNOend);
                if (ds == null || ds.Count <= 0 )
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0021"));
                }
                return ResultsExtensions.GetSuccessJson(ds);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0002"));
            }
        }

        /// <summary>
        /// 根据商品编号和侧扫口及侧扫口左侧或右侧，查找该侧扫口订单需要该商品的总数量
        /// </summary>
        /// <param name="goodsSn"></param>
        /// <param name="sideSweep"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetTotalGoodsBySn(string goodsSn,int sideSweep,int right)
        {


            if (string.IsNullOrEmpty(goodsSn) || sideSweep>3 || sideSweep<0 || right>2 || right<0)
                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0003"));
            MB.Util.TraceEx.Write(goodsSn);
            try
            {
                var ds = new BOrderPick().GetTotalGoodsBySn(goodsSn, sideSweep, right);
                if (ds == null || ds.Tables.Count<0)
                {
                    return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0021"));
                }

                if (ds.Tables[0].Rows.Count <= 0)
                {
                    string side = string.Empty;
                    if (sideSweep == 0)
                    {
                        if (right == 0)
                        {
                            List<object> list = new List<object>();
                            list.Add(new { SIDESWEEP = "1,右侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "2,右侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "3,右侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "1,左侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "2,左侧", ITEMCODE = goodsSn, QTY = 0 });
                            return ResultsExtensions.GetSuccessJson(list);
                        }

                        if (right == 1)
                        {
                            List<object> list = new List<object>();
                            list.Add(new { SIDESWEEP = "1,右侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "2,右侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "3,右侧", ITEMCODE = goodsSn, QTY = 0 });
                            return ResultsExtensions.GetSuccessJson(list);
                        }

                        if (right == 2)
                        {
                            List<object> list = new List<object>();
                            list.Add(new { SIDESWEEP = "1,左侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = "2,左侧", ITEMCODE = goodsSn, QTY = 0 });
                            return ResultsExtensions.GetSuccessJson(list);
                        }
                    }

                    side = sideSweep.ToString();
                    if (right == 0)
                    {
                        if (sideSweep <= 2)
                        {
                            List<object> list = new List<object>();
                            list.Add(new { SIDESWEEP = side + ",右侧", ITEMCODE = goodsSn, QTY = 0 });
                            list.Add(new { SIDESWEEP = side + ",左侧", ITEMCODE = goodsSn, QTY = 0 });
                            return ResultsExtensions.GetSuccessJson(list);
                        }
                    }
                    if (right == 1)
                    {
                        List<object> list = new List<object>();
                        list.Add(new { SIDESWEEP = side + ",右侧", ITEMCODE = goodsSn, QTY = 0 });
                        return ResultsExtensions.GetSuccessJson(list);
                    }
                    if (right == 2)
                    {
                        List<object> list = new List<object>();
                        list.Add(new { SIDESWEEP = side + ",左侧", ITEMCODE = goodsSn, QTY = 0 });
                        return ResultsExtensions.GetSuccessJson(list);
                    }
                }
                return ResultsExtensions.GetSuccessJson(ds.Tables[0]);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);

                return ResultsExtensions.GetFailJson(Setting.Instance.getMessageByKey("O0002"));
            }
        }
    }
}